<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>字典管理</title>
    <link rel="stylesheet" href="${ctxPath}/assets/libs/layui/css/layui.css"/>
    <link rel="stylesheet" href="${ctxPath}/assets/module/admin.css"/>
    <link rel="stylesheet" href="${ctxPath}/assets/module/formSelects/formSelects-v4.css"/>
</head>
<body>
<!-- 正文开始 -->
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body">
            <div class="layui-form toolbar">

                <div class="layui-inline">
                    <div class="layui-form-item">
                        <label class="layui-form-label w-auto">编码:</label>
                        <div class="layui-input-inline mr0">
                            <input id="dictCode" class="layui-input" type="text" placeholder="请输入"/>
                        </div>
                    </div>
                </div>
                <div class="layui-inline">
                    <div class="layui-form-item">
                        <label class="layui-form-label w-auto">内容:</label>
                        <div class="layui-input-inline mr0">
                            <input id="remark" class="layui-input" type="text" placeholder="请输入"/>
                        </div>
                    </div>
                </div>


                <div class="layui-inline">
                    <button id="btnSearch" class="layui-btn icon-btn"><i class="layui-icon">&#xe615;</i>查询</button>
                    <button id="btnReset" class="layui-btn icon-btn"><i class="layui-icon">&#xe669;</i>重置</button>
                </div>


                <div class="layui-form-item" style="margin-top: 20px">
                    <table class="layui-table" id="dictTable" lay-filter="dictTable" style="margin-top: 30px"></table>
                </div>

            </div>
        </div>
    </div>
</div>

<!-- 表格操作列 -->
<script type="text/html" id="dictTableBar">
    <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="update">编辑</a>
</script>

<!-- 编辑 表单弹窗 -->
<script type="text/html" id="dictEditLayer">
    <form id="dictForm" lay-filter="dictForm" class="layui-form model-form dictForm"
          style="margin-left: 70px;height: 500px">
        <input name="id" type="hidden"/>
        <div class="layui-form-item">
            <label class="layui-form-label"><span style="color: red">*</span>字典名称:</label>
            <input name="dictName" placeholder="请输入" type="text" class="layui-input" lay-verType="tips"
                   autocomplete="off" lay-verify="required" style="width: 300px" />
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label"><span style="color: red">*</span>描述:</label>
            <input name="remark" placeholder="请输入" type="text" class="layui-input" lay-verType="tips"
                   autocomplete="off" lay-verify="required" style="width: 300px" />
        </div>

        <div class="layui-form-item text-right">
            <button class="layui-btn layui-btn-primary" type="button" ew-event="closePageDialog">取消</button>
            <button class="layui-btn" lay-filter="dictFormSubmit" lay-submit>保存</button>
        </div>

    </form>
</script>

<!-- js部分 -->
<script type="text/javascript" src="${ctxPath}/assets/libs/layui/layui.js"></script>
<script type="text/javascript" src="${ctxPath}/assets/js/common.js"></script>

<script>
    layui.use(['layer', 'form', 'table', 'admin', 'laydate', 'upload', 'jquery', 'formSelects' ,'excel'],function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var table = layui.table;
        var admin = layui.admin;
        var laydate = layui.laydate;
        var upload = layui.upload;
        var formSelects = layui.formSelects;


        var insTb = table.render({
            elem: '#dictTable',
            url: '/admin/dict/dictList',
            page: true,
            cellMinWidth: 100,
            text: {none: '暂无数据'},
            cols: [[
                {type: 'checkbox'},
                {field: 'id', title: 'id' , width:50,hide: true},
                {field: 'dictCode', title: '编码' , width:200},
                {field: 'dictName', title: '内容' , width:150},
                {field: 'remark', title: '描述' },
                {field: 'createdDate', title: '创建时间' , width:200},
                {align: 'center', toolbar: '#dictTableBar', title: '操作', width: 100}
            ]]
        });



        //搜索
        $('#btnSearch').click(function () {
            var dictCode = $('#dictCode').val();
            var remark = $('#remark').val();
            insTb.reload({
                where: {
                    dictCode: dictCode,
                    remark: remark,
                }
            });
        });

        // 重置
        $('#btnReset').click(function () {
            $("#dictCode").val("");
            $("#remark").val("");
            window.location.reload();
        });

        // 工具条点击事件
        table.on('tool(dictTable)', function (obj) {
            var data = obj.data;
            var layEvent = obj.event;

            switch (obj.event) {
                // 充值
                case 'update':
                    editDict(data);
                    break;
            }
        });

        // 显示编辑表单弹窗
        function editDict(data) {
            admin.open({
                type: 1,
                title: (data ? '修改' : '新建') + '字典',
                area: '650px',
                content: $('#dictEditLayer').html(),
                success: function (layero, dIndex) {

                    // 回显数据
                    if (data) {
                        form.val('dictForm', data);
                    }
                    form.render();

                    form.on('submit(dictFormSubmit)', function (data) {
                        layer.close(dIndex);
                        if(data){
                            ajaxCommon('/admin/dict/update', data.field);
                        }else{
                            //ajaxCommon('/gameUser/add', data.field);
                        }
                        insTb.reload();
                        return false;
                    });
                }
            });
        }



    })

</script>

</body>
</html>